#ifndef MYVECTOR_HY
#define MYVECTOR_HY


#include <math.h>

class CVector3D
{
private:
	float x, y, z;
	
public:
	inline CVector3D()
	{
		x = 0;
		y = 0;
		z = 0;
	}

	inline CVector3D(float a, float b, float c)
	{
		x = a;
		y = b;
		z = c;
	}

	inline ~CVector3D() {}

	inline void Set(float a, float b, float c)
	{
		x = a;
		y = b;
		z = c;
	}

	inline void Set(const CVector3D& vec)
	{
		x = vec.x;
		y = vec.y;
		z = vec.z;
	}

	inline float Magnitude2()
	{
		return x*x + y*y + z*z;
	}

	inline float Magnitude()
	{
		float sq = Magnitude2();
		if (sq != 0)
			return sqrt(sq);
		else
			return 0;
	}

	inline void Normalize()
	{
		float len = Magnitude();
		if(len != 0 && len != 1.0)
		{
			x = x/len;
			y = y/len;
			z = z/len;
		}
	}

	inline bool operator==(const CVector3D& vec)
	{
		if(x==vec.x && y==vec.y && z==vec.z)
			return true;
		return false;
	}

	inline CVector3D& operator=(const CVector3D& vec)
	{
		x = vec.x;
		y = vec.y;
		z = vec.z;
		return *this;
	}

	inline CVector3D& operator+=(const CVector3D& vec)
	{
		x += vec.x;
		y += vec.y;
		z += vec.z;
		return *this;
	}

	inline CVector3D operator+(const CVector3D& vec)
	{
		return CVector3D(x+vec.x, y+vec.y, z+vec.z);
	}

	inline CVector3D& operator-=(const CVector3D& vec)
	{
		x -= vec.x;
		y -= vec.y;
		z -= vec.z;
		return *this;
	}

	inline CVector3D operator-(const CVector3D& vec)
	{
		return CVector3D(x-vec.x, y-vec.y, z-vec.z);
	}
	
	inline CVector3D operator-(void) const
	{
		return CVector3D(-x, -y, -z);
	}

	inline CVector3D operator^(const CVector3D& vec)
	{
		return CVector3D(y*vec.z - z*vec.y,
						 -x*vec.z + z*vec.x,
						 x*vec.y - y*vec.x);
	}

	inline float operator*(const CVector3D& vec)
	{
		return x*vec.x + y*vec.y + z*vec.z;
	}

	inline CVector3D operator*(const float factor)
	{
		return CVector3D(x*factor, y*factor, z*factor);
	}

	inline CVector3D operator/(const float factor)
	{
		return CVector3D(x/factor, y/factor, z/factor);
	}
};

#endif